{block name=head}
<style type="text/css">
</style>
{/block} {block name=body}
<div id="member-news-bulletin">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                {$listing_content1}
            </div>
        </div>
    </div>
</div>
<div id="maincont">
    <div class="container">
        <div class="row">
            <!--<div class="col-sm-12" id="breadcrumbs">{include file='breadcrumbs.tpl'}</div>
            <div class="col-sm-12">
                <h1>{$listing_name}</h1>
            </div>-->
            <div class="col-sm-12">
                {if $error}
                <div class="alert alert-danger fade in text-center">
                    <button class="close" aria-hidden="true" data-dismiss="alert" type="button">&times;</button>
                    <strong>{$error}</strong>
                </div>
                {/if} {if $notice}
                <div class="alert alert-success fade in text-center">
                    <button class="close" aria-hidden="true" data-dismiss="alert" type="button">&times;</button>
                    <strong>{$notice}</strong>
                </div>
                {/if}
                <div id="tab-container" style="position: relative;">
                    <ul class="nav nav-tabs responsive" id="account-tab">
                        <li class="active"><a href="#enrolments" data-toggle="tab">课程信息</a></li>
                        <li><a href="#orders" data-toggle="tab">我的订单</a></li>
                        {if !$user.social_id}
                        <li><a href="#contact" data-toggle="tab">个人信息</a></li>
                        <li><a href="#student" data-toggle="tab">学生信息</a></li>
                        <li><a href="#password" data-toggle="tab">修改密码</a></li>
                        {/if}
                    </ul>
                    <a href="/enrol" class="green-btn new-enrolment-btn text-center" id="newenrol1"><span>报名新的课程</span></a>
                    <div class="tab-content responsive">
                        <div class="tab-pane active" id="enrolments">
                            <div class="tab-content-open">
                                <div class="current-term-enrolments">
{assign var='CLASSLIST' value=''}
{assign var='hasEnrol' value=0}
{foreach $students as $student}
    {foreach $student.curTerm_enrolments as $curterm}
        {foreach $curterm.classterms as $ct}
            {assign var='stdclss' value=$student.student_id|cat:'-'|cat:$ct.class_object_id|cat:'-'|cat:$ct.term_object_id}
            {if $ct.term_name && $ct.class_name && !$stdclss|in_array:$CLASSLIST}
                {assign var='hasEnrol' value=1}
                {append var='CLASSLIST' value=$stdclss}
                                    <div class="members-class-detail text-center">
                                        <h3>{$ct.class_name} | {$ct.term_name}</h3>
                                        <p><strong>{$student.student_name} {$student.student_surname}</strong>
                                            <br>
                                            <span class="{if $ct.enrolment_type eq 'S' || $ct.enrolment_type eq 'MV'}yellow-tag{else}orange-tag{/if}">{$ct.enrolment_type_name} 课程</span>
                                        </p>
                                        <p>
                {if $ct.enrolment_type eq 'T' }
                    {foreach $curterm.enrolments as $enrol}
                        {if $enrol.enrolment_type eq 'T' && $enrol.enrolment_term_object_id eq $ct.term_object_id && $enrol.enrolment_class_object_id eq $ct.class_object_id}
                            {getdatebyweekdaystartdate weekday=$ct.class_weekday startdate=$ct.term_start_date weeksafter=$enrol.enrolment_week-1 dateformat='l, d M Y'}
                                            <br>
                        {/if}
                    {/foreach}
                {/if}
                {if $ct.enrolment_type eq 'MK'}
                    {foreach $curterm.enrolments as $enrol}
                        {if $enrol.enrolment_type eq 'MK' && $enrol.enrolment_term_object_id eq $ct.term_object_id && $enrol.enrolment_class_object_id eq $ct.class_object_id}
                            {getdatebyweekdaystartdate weekday=$ct.class_weekday startdate=$ct.term_start_date weeksafter=$enrol.enrolment_week-1 dateformat='l, d M Y'}
                                            <br>
                        {/if}
                    {/foreach}
                {/if}
                                            {$ct.location_state} {$ct.location_suburb} {$ct.location_country} {$ct.location_street}  {$ct.location_postcode}
                                            <br>
                                            <a href="http://api.map.baidu.com/marker?location={$ct.location_longitude},{$ct.location_latitude}&title={$ct.location_name}&content=&output=html&src=rsgk" target="_blank">查看地图</a>
                                        </p>
                                        {if $ct.enrolment_type eq 'S' || $ct.enrolment_type eq 'MV'}
                                        <p>不能按时参加？<a href="/contact-us?enquiry=您好,澳睿跑团队!%0D%0A%0D%0A我想要申请该课程的补课:%20{$DOMAIN|cat:'/'|cat:$ct.term_url|cat:'/'|cat:$ct.class_url|cat:''|escape:'url'}%0D%0A%0D%0A请与我联系协商合适的时间，非常感谢。#enroltrialhead">申请补课</a></p>{/if}
                                        <div class="col-sm-6 col-sm-offset-3">
                                            {if $ct.enrolment_type eq 'T'}
                                            <button type="button" onclick="EnrolFromMembersArea({$student.student_id},{$ct.term_object_id},{$ct.class_object_id},'/enrol/classterm/{$ct.term_url}/{$ct.class_url}')" class="enquire"><span>报名该课程</span></button>
                                            {elseif $ct.enrolment_type eq 'MV' || $ct.enrolment_type eq 'S'} {if $ct.reenrol && $ct.reenrol.term_url}
                                            <button type="button" onclick="EnrolFromMembersArea({$student.student_id},{$ct.term_object_id},{$ct.class_object_id},'/enrol/classterm/{$ct.reenrol.term_url}/{$ct.class_url}?reenrol=1')" class="enquire"><span>再次报名该课程</span></button>
                                            <span class="mini">或</span>
                                            <a href="/enrol" class="green-btn new-enrolment-btn text-center"><span>报名其他课程</span></a> {/if} {/if}
                                        </div>
                                    </div>
                                    <div class="clear"></div>
            {/if}
        {/foreach}
    {/foreach}
{/foreach}
{if $hasEnrol eq 0}
                                    <div class="no-active">
                                        您现在没有进行中的课程，<a href="/enrol">点击这里</a> 去预约报名吧。
                                    </div>
{/if}
                                </div>
                            </div>
                        </div>
                        <!--===+++===+++===+++===+++===+++ TRANSACTION HISTORY TAB +++===+++===+++===+++===+++====-->
                        <div class="tab-pane" id="orders">
                            <div class="tab-content-open">
                                {include file='table-payments.tpl'}
                            </div>
                        </div>
                        {if !$user.social_id}
                        <!--===+++===+++===+++===+++===+++ MY ACCOUNT TAB +++===+++===+++===+++===+++====-->
                        <div class="tab-pane" id="contact">
                            <div class="tab-content-open">
                                <!--===+++===+++===+++===+++===+++ UPDATE DETAILS +++===+++===+++===+++===+++====-->
                                <div class="update-contact-details">
                                    <form class="form-horizontal" id="update-details-form" role="form" accept-charset="UTF-8" action="/process/user" method="post">
                                        <input type="hidden" value="updateDetails" name="action" id="action" />
                                        <input type="hidden" name="formToken" id="formToken" value="{$token}" />
                                        <div class="enroltrialmain">
                                            <div class="row">
                                                <div class="col-sm-8 col-sm-offset-2">
                                                    <div class="row">
                                                        <div class="col-sm-6 form-group">
                                                            <label for="gname">{$lang.contact.name}</label>
                                                            <input type="text" value="{if $post}{$post.gname}{else}{$user.gname}{/if}" id="gname" name="user_gname" required />
                                                            <span class="help-block"></span>
                                                        </div>
                                                        <div class="col-sm-6 form-group">
                                                            <label for="sex">{$lang.contact.sex}</label>
                                                            <select id="sex" name="user_sex" class="required form-control">
                                                                <option value="1" {if $user.sex eq 1}selected="selected" {/if}>先生</option>
                                                                <option value="2" {if $user.sex eq 2}selected="selected" {/if}>女士</option>
                                                            </select>
                                                            <span class="help-block"></span>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-sm-6 form-group">
                                                            <label for="email">{$lang.contact.email}</label>
                                                            <input type="email" value="{$user.email}" id="email" name="user_email" />
                                                            <span class="help-block"></span>
                                                        </div>
                                                        <div class="col-sm-6 form-group">
                                                            <label for="phone">{$lang.contact.phone}</label>
                                                            <input type="text" value="{$user.phone}" id="phone" name="user_phone" disabled="disabled"/>
                                                            <span class="help-block"></span>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-sm-3 form-group">
                                                            <label for="state">{$lang.contact.province}</label>
                                                            <!-- <input type="text" value="{if $post}{$post.state}{else}{$user.state}{/if}" id="state" name="state" required /> -->
                                                            <select id="state" name="address_state" class="required form-control">
                                                                <option value="">请选择</option>
                                                                {foreach $states as $state }
                                                                <option value="{$state.value}" {if $address && $address.S.address_state eq $state.value}selected="selected" {/if}>{$state.value}</option>
                                                                {/foreach}
                                                            </select>
                                                        </div>
                                                        <div class="col-sm-3 form-group">
                                                            <label for="suburb">{$lang.contact.city}</label>
                                                            <select id="suburb" name="address_suburb" class="shipping-select-req required form-control">
                                                                <option value="">请选择</option>
                                                            </select>
                                                        </div>
                                                        <div class="col-sm-6 form-group">
                                                            <label for="country">{$lang.contact.country}</label>
                                                            <select id="country" name="address_country" class="shipping-select-req required form-control">
                                                                <option value="">请选择</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-sm-6 form-group">
                                                            <label for="street">{$lang.contact.street_no}</label>
                                                            <input type="text" value="{if $post}{$post.street}{else}{$address.S.address_line1}{/if}" id="street" name="address_line1" required />
                                                            <span class="help-block"></span>
                                                        </div>
                                                        <div class="col-sm-6 form-group">
                                                            <label for="postcode">{$lang.contact.postcode}</label>
                                                            <input type="text" value="{if $post}{$post.postcode}{else}{$address.S.address_postcode}{/if}" id="postcode" name="address_postcode"/>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="form-group">
                                                            <div class="col-sm-12 cbout">
                                                                <input id="promo1" name="user_want_promo" type="checkbox" {if $post}{if $post.user_want_promo}checked="checked" {/if}{else}{if $user.user_want_promo eq 1}checked="checked" {/if}{/if} />
                                                                <label for="promo1" class="chklab">请给我发送宣传邮件。</label>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="form-group">
                                                            <div class="col-sm-12">
                                                                <button type="submit" class="enquire"><span>更新联系信息</span></button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        {/if}
                        <!--===+++===+++===+++===+++===+++ UPDATE STUDENTS TAB +++===+++===+++===+++===+++====-->
                        <div class="tab-pane" id="student">
                            <div class="tab-content-open">
                                <!-- <div class="row">
                                    <div class="col-sm-offset-3 col-sm-3 text-center">
                                        <button type="button" type="button" class="enquire" onclick="AddStudent('student-form')">添加新学生</button>
                                    </div>
                                </div> -->
                                {if $students}
                                {assign var='cnt' value=0 }
                                {foreach $students as $student}
                                {assign var='cnt' value=$cnt+1 }
                                <div class="update-student-details">
                                    <form class="form-horizontal student-forms" id="update-student-form{$student.student_id}" data-attr-id="update-student-form" role="form" accept-charset="UTF-8" action="/process/user" method="post">
                                        <input type="hidden" value="updateStudentDetails" name="action" id="action" />
                                        <input type="hidden" name="formToken" id="formToken" value="{$token}" />
                                        <input type="hidden" name="student[student_id]" value="{$student.student_id}" />
                                        <div class="enroltrialmain addnew">
                                            <div class="row">
                                                <div class="col-sm-8 col-sm-offset-2">
                                                    <div class="row">
                                                        <div class="col-sm-6 col-md-3 form-group">
                                                            <label>{$lang.contact.name}</label>
                                                            <input type="text" value="{$student.student_name}" class="form-control new_name" id="gname{$cnt}" name="student[student_name]" required>
                                                        </div>
                                                        <div class="col-sm-6 col-md-3 form-group">
                                                            <label for="sex">{$lang.contact.sex}</label>
                                                            <select id="sex" name="student[student_sex]" class="required form-control">
                                                                <option value="1" {if $post && $post.sex eq 1}selected="selected" {/if}>男孩</option>
                                                                <option value="2" {if $post && $post.sex eq 2}selected="selected" {/if}>女孩</option>
                                                            </select>
                                                            <span class="help-block"></span>
                                                        </div>
                                                        <div class="col-sm-12 col-md-6 form-group">
                                                            <label>* 生日:</label>
                                                            <input type="hidden" value="{$student.student_dob}" name="student[student_dob]" id="dob{$cnt}">
                                                            <div>
                                                                <span class="form-group to">
                                                                    <select id="dobyear{$cnt}" name="year" class="form-control required" onchange="$('#dob{$cnt}').val( $('#dobyear{$cnt}').val()+'-'+$('#dobmonth{$cnt}').val()+'-'+$('#dobday{$cnt}').val() )">
                                                                        <option value="">年</option>
                                                                        {assign var=initYear value='Y'|date}
                                                                        {for $year=$initYear-7 to $initYear-2}
                                                                            <option value="{$year}" {if $student.student_dob && $student.student_dob neq '0000-00-00' && $student.student_dob|date_format:'%Y' eq $year}selected="selected"{else}{if $search.year eq $year}selected="selected"{/if}{/if}>{$year} 年</option>
                                                                        {/for}
                                                                    </select>
                                                                </span>
                                                                <span class="form-group ts" id="monthout">
                                                                    <select id="dobmonth{$cnt}" name="month" class="form-control required" onchange="$('#dob{$cnt}').val( $('#dobyear{$cnt}').val()+'-'+$('#dobmonth{$cnt}').val()+'-'+$('#dobday{$cnt}').val() )">
                                                                        <option value="">月</option>
                                                                        {for $month=1 to 12}
                                                                        <option value="{if $month lt 10}0{/if}{$month}" {if $student.student_dob && $student.student_dob neq '0000-00-00' && $student.student_dob|date_format:'%m' eq $month}selected="selected"{else}{if $search.month eq $month}selected="selected"{/if}{/if}>{$month} 月</option>
                                                                        {/for}
                                                                    </select>
                                                                </span>
                                                                <span class="form-group ts">
                                                                    <select id="dobday{$cnt}" name="day" class="form-control required" onchange="$('#dob{$cnt}').val( $('#dobyear{$cnt}').val()+'-'+$('#dobmonth{$cnt}').val()+'-'+$('#dobday{$cnt}').val() )">
                                                                        <option value="">日</option>
                                                                        {for $day=1 to 31}
                                                                        <option value="{if $day lt 10}0{/if}{$day}" {if $student.student_dob && $student.student_dob neq '0000-00-00' && $student.student_dob|date_format:'%d' eq $day}selected="selected"{else}{if $search.day eq $day}selected="selected"{/if}{/if}>{$day} 日</option>
                                                                        {/for}
                                                                    </select>
                                                                </span>
                                                                
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-sm-12 form-group">
                                                            <label>身体状况:</label>
                                                            <textarea class="form-control" name="student[student_medical]" maxlength="255" rows="2">{$student.student_medical}</textarea>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-sm-12 form-group">
                                                        {if $student.student_object_id}已绑定会员卡：<span class="glyphicon glyphicon-credit-card"></span> {$student.student_object_id}{else}未绑定会员卡，<a href="javascript:void()" onclick="bindCard(this)">点击现在绑定。</a>{/if}
                                                        </div>
                                                    </div>

                                                    <div class="row">
                                                        <div class="form-group">
                                                            <div class="col-sm-12 error-alert" style="display:none;">
                                                                <div class="alert alert-danger fade in text-center">
                                                                    <button class="close" aria-hidden="true" data-dismiss="alert" type="button">&times;</button>
                                                                    <strong></strong>
                                                                </div>
                                                            </div>
                                                            <div class="col-sm-12 success-alert" style="display:none;">
                                                                <div class="alert alert-success fade in text-center">
                                                                    <button class="close" aria-hidden="true" data-dismiss="alert" type="button">&times;</button>
                                                                    <strong></strong>
                                                                </div>
                                                            </div>
                                                            <div class="col-sm-12">
                                                                <button type="submit" type="submit" class="enquire">更新信息</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                                {/foreach}
                                <br>
                                {/if}
                            </div>
                        </div>
                        <!--===+++===+++===+++===+++===+++ UPDATE PASSWORD TAB +++===+++===+++===+++===+++====-->
                        <div class="tab-pane" id="password">
                            <div class="tab-content-open">
                                <div class="update-password-details">
                                    <form class="form-horizontal" id="update-pass-form" role="form" accept-charset="UTF-8" action="/process/user" method="post">
                                        <input type="hidden" value="updatePassword" name="action" id="action" />
                                        <input type="hidden" name="formToken" id="formToken" value="{$token}" />
                                        <div class="enroltrialmain">
                                            <div class="row">
                                                <div class="col-sm-8 col-sm-offset-2">
                                                    <div class="row">
                                                        <div class="col-sm-6 form-group">
                                                            <label for="password">原始密码</label>
                                                            <input type="password" value="" id="old_password" name="old_password" autocomplete="off" required> <a class="showhide" style="line-height: 34px; position: absolute;" href="javascript:void(0);" onclick="if($(this).html() == '显示'){ $(this).closest('div').find('input[name=old_password]').get(0).type='text';$(this).html('隐藏'); }else{ $(this).closest('div').find('input[name=old_password]').get(0).type='password';$(this).html('显示'); }">显示</a> <span class="help-block"></span>
                                                        </div>
                                                        <div class="col-sm-6 form-group">
                                                            <label for="password">新密码</label>
                                                            <input type="password" value="" id="password2" name="password" autocomplete="off" required> <a class="showhide" style="line-height: 34px; position: absolute; " href="javascript:void(0);" onclick="if($(this).html() == '显示'){ $(this).closest('div').find('input[name=password]').get(0).type='text';$(this).html('隐藏'); }else{ $(this).closest('div').find('input[name=password]').get(0).type='password';$(this).html('显示'); }">显示</a> <span class="help-block"></span>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="form-group">
                                                            <div class="col-sm-12">
                                                                <button type="submit" type="submit" class="enquire">更新密码</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{* Place additional javascript here so that it runs after General JS includes *} {block name=tail}
<script type="text/javascript" src="/includes/js/responsive-tabs.js"></script>
<script type="text/javascript">
function AddStudent(formID) {
    //$('body').css('cursor', 'wait');
    //$('#' + formID).find('.btn').addClass('disabled');
    var cnt = 1;//$("#cnt").val();
    $.ajax({
        type: "POST",
        url: "/process/cart",
        cache: false,
        data: 'action=studentTemplate&cnt=' + cnt,
        dataType: "html",
        success: function(data, textStatus) {
            try {
                var obj = $.parseJSON(data);
                if (obj.success) {
                    $('#student-wrapper').append(obj.template);
                    // $(".existing-student").hide();
                    // $('.saveFake').hide();
                    // $('.stuformbuttons').hide();
                    // $('#student-form').validate();
                    // cnt++;
                    // $("#cnt").val(cnt);
                    // $('select').selectBoxIt();
                    // $('#dob' + cnt).val($('#dobyear' + cnt).val() + '-' + $('#dobmonth' + cnt).val() + '-' + $('#dobday' + cnt).val());
                }
            } catch (err) {}
            //$('body').css('cursor', 'default');
            //$('#' + formID).find('.btn').removeClass('disabled');
        },
        error: function() {
            //$('body').css('cursor', 'default');
            //$('#' + formID).find('.btn').removeClass('disabled');
            console.log('AJAX error');
        }
    });
}

function bindCard(which){
    console.log(which);
}

$(document).ready(function() {
    fakewaffle.responsiveTabs(['xs']);
    $('select').selectBoxIt();

    var oProvince = $("select#state");
    var oCity = $("select#suburb");
    var oCountry = $("select#country");

    var city = function(){
        var n = oProvince.get(0).selectedIndex;
        var id = oProvince.find("option:selected").val();
        $.ajax({
            url: "/process/regionsuburbs",
            dataType: "json",
            data: {
                name: id,
                type:"suburb"
            },
            success: function( data ) {
                oCity.data("selectBox-selectBoxIt").remove();
                oCity.data("selectBox-selectBoxIt").add(data);
{if $address && $address.S.address_suburb}
                oCity.data("selectBox-selectBoxIt").selectOption("{$address.S.address_suburb}");
{/if}
                //district();
            }
        });
    }

    var district = function(){
        var n = oCity.get(0).selectedIndex;
        var id = oCity.find("option:selected").val();
        $.ajax({
            url: "/process/regionsuburbs",
            dataType: "json",
            data: {
                name: id,
                type:"country"
            },
            success: function( data ) {
                oCountry.data("selectBox-selectBoxIt").remove();
                oCountry.data("selectBox-selectBoxIt").add(data);
{if $address && $address.S.address_country}
                oCountry.data("selectBox-selectBoxIt").selectOption("{$address.S.address_country}");
{/if}
            }
        });
    }

    city();
    oProvince.change(function(){
        city();
    });

    oCity.change(function(){
        district();
    });

    $('#update-pass-form').validate();
    $('#update-details-form').validate();

    $('.student-forms').each(function() {
        $(this).validate();
    });

    var setTab = window.location.hash;
    if (setTab == '#notice' || setTab == '#error') $('#account-tab a[href="#password"]').tab('show');
    if (setTab == '#enrolments') $('#account-tab a[href="#enrolments"]').tab('show');
    if (setTab == '#orders') $('#account-tab a[href="#orders"]').tab('show');
    if (setTab == '#contact') $('#account-tab a[href="#contact"]').tab('show');
    if (setTab == '#student') $('#account-tab a[href="#student"]').tab('show');
    if (setTab == '#password') $('#account-tab a[href="#password"]').tab('show');
});
</script>
{/block}
